package com.hippomeetsskunk.savanna.types.goal;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Set;

import org.apache.log4j.Logger;

import com.hippomeetsskunk.savanna.types.meta.ResourceType;
import com.hippomeetsskunk.savanna.types.person.Person;
import com.hippomeetsskunk.savanna.types.person.Skills;
import com.hippomeetsskunk.savanna.types.resource.SimObject;

/**
 * a goal is a defined piece of work, able to execute on its own.
 * @author SRZCHX
 *
 */
public class ImproveGoal extends AbstractGoal implements Goal {
	final private static Logger logger = Logger.getLogger(ImproveGoal.class);
	final private SimObject object;
	
	public ImproveGoal(Person worker, SimObject object, Set<ResourceType> resources, Skills requiredSkills){
		super(worker, requiredSkills, resources, object.getIntrinsicValue(), 1.0 / object.getQuality());
		this.object = object;
	}
	
	public void execute(){
		logger.debug("increased quality of " + object + " to " + object.getQuality());
		final double work = getRequiredSkills().getSkillFactor(getWorker());
		object.improve(work, getWorker().getResources(getRequiredResources()));
	}
	
	public SimObject getObject() {
		return object;
	}

	@Override
	public String toString() {
		NumberFormat nf = new DecimalFormat();
		nf.setMaximumFractionDigits(2);
		return "Improve(" + object + "[q=" + nf.format(object.getQuality()) + "])";
	}

}
